function [sadresult]=queryset_using_PAA(k,matfile)
load(matfile);
%load  ECG32_16.mat;
%load  syndata10_128.mat;
%load  income12_8.mat;
result=[];

segnum=6;
dataPAA=myPAA(origdata, segnum);
queryPAA=myPAA(queryset, segnum);

for queryidx=1:size(queryset,1)
    
    query=queryset(queryidx,:);
    
    
    belongto=ceil(queryidx/100);
    belongto=[(belongto-1)*100+1:belongto*100];
    
    [closest_k_matches]=closestKwith(queryPAA(queryidx,:),dataPAA,k);
    
    %find true closest_k_matches in ED space
    for i=1:size(origdata,1)
    
    
        DistinED(i)=distance(query, origdata(i,:));
        
    
    end
    [valuesorted indexsorted]=sort(DistinED);
    TrueMatches=indexsorted(1:k);
    
    pre=length(intersect(closest_k_matches,TrueMatches))/length(closest_k_matches);
    portioninbelongto=length(intersect(closest_k_matches,belongto))/length(closest_k_matches);
    portionTrueMatchesinbelongto=length(intersect(TrueMatches,belongto))/length(TrueMatches);
   
    
    realbestmatch=TrueMatches(1);
    if ismember(realbestmatch,closest_k_matches)
       isbestincluded=1; 
    else
       isbestincluded=0;  
    end
    clear temp;
    temp=[pre portioninbelongto portionTrueMatchesinbelongto isbestincluded];
    
    result=[result;temp];
    
end  %for queryidx=1:Numberofsamples
disp 'pre portioninbelongto portionTrueMatchesinbelongto isbestincluded'
sadresult=mean(result);







